package com.wlyuan.open.scanner;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class MyBatisGenerator {
    public void generate() {
        FastAutoGenerator.create("jdbc:sqlserver://192.168.1.253:1433;DatabaseName=WLY;trustServerCertificate=true", "WLY", "Wly2.techns@907")
                .globalConfig(builder -> {
                    builder.author("yuanjie") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://codeGen"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.wlyuan.open.scanner.dao") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://codeGen")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    String[] tableNames = {
                            "t_quotation_relation"};
                    builder.addInclude(tableNames) // 设置需要生成的表名
                            .addTablePrefix("TMS_", "t_")
                            .controllerBuilder()
                            .enableRestStyle()
                            .enableHyphenStyle()
                            .entityBuilder()
                            .enableLombok()
                            .formatFileName("%sDO")
                            .serviceBuilder()
                            .formatServiceFileName("%sDOService")
                            .formatServiceImplFileName("%sDOServiceImpl");
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }

    public static void main(String[] args) {
        new MyBatisGenerator().generate();
    }
}
